package com.hotel.project.gateway.apollo;


import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import com.ctrip.framework.apollo.model.ConfigChange;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ApolloConfig -- 阿波罗配置
 *
 * @author: peng.ni
 * @date: 2022/04/13
 */
@Configuration
@Slf4j
public class ApolloConfig {
    @Bean
    public void config() {
        // config instance is singleton for each namespace and is never null
        Config config = ConfigService.getAppConfig();
        // 注册时间监听
        config.addChangeListener(changeEvent -> {
            log.info("Changes for namespace " + changeEvent.getNamespace());
            for (String key : changeEvent.changedKeys()) {
                ConfigChange change = changeEvent.getChange(key);
                log.info("Found change - key: {}, oldValue: {}, newValue: {}, changeType: {}", change.getPropertyName(), change.getOldValue(), change.getNewValue(), change.getChangeType());
            }
        });
    }
}
